package com.neuedu.cockpit.controller;

import com.neuedu.cockpit.domain.HmCarInfo;
import com.neuedu.cockpit.domain.HmCarState;
import com.neuedu.cockpit.service.IHmCarInfoService;
import com.neuedu.cockpit.service.IHmCarStateService;
import com.neuedu.common.annotation.Log;
import com.neuedu.common.core.controller.BaseController;
import com.neuedu.common.core.domain.AjaxResult;
import com.neuedu.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 车辆状态Controller
 *
 * @author neuedu
 * @date 2024-04-29
 */
@RestController
@RequestMapping("/cockpit/state")
public class HmCarStateController extends BaseController {
    @Autowired
    private IHmCarStateService hmCarStateService;

    @Autowired
    private IHmCarInfoService hmCarInfoService;

    /**
     * 查询车辆状态列表
     */
//    @PreAuthorize("@ss.hasPermi('train:state:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(HmCarState hmCarState)
//    {
//        startPage();
//        List<HmCarState> list = hmCarStateService.selectHmCarStateList(hmCarState);
//        return getDataTable(list);
//    }

    /**
     * 导出车辆状态列表
     */
//    @PreAuthorize("@ss.hasPermi('train:state:export')")
//    @Log(title = "车辆状态", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, HmCarState hmCarState)
//    {
//        List<HmCarState> list = hmCarStateService.selectHmCarStateList(hmCarState);
//        ExcelUtil<HmCarState> util = new ExcelUtil<HmCarState>(HmCarState.class);
//        util.exportExcel(response, list, "车辆状态数据");
//    }

    /**
     * 获取车辆状态详细信息
     */
    @GetMapping("/{carVin}")
    public AjaxResult getInfo(@PathVariable String carVin) {
        HmCarInfo hmCarInfo = hmCarInfoService.selectHmCarInfoByUserIdAndCarVin(getUserId(), carVin);
        if (hmCarInfo != null) {
            HmCarState hmCarState = hmCarStateService.selectHmCarStateByCarId(hmCarInfo.getId());
            return AjaxResult.success(hmCarState);
        } else {
            return AjaxResult.error("当前用户未绑定车辆");
        }
    }

    /**
     * 获取车辆状态详细信息
     */
    @GetMapping("/byCarId/{carId}")
    public AjaxResult getInfoByCarId(@PathVariable Long carId) {
        HmCarState hmCarState = hmCarStateService.selectHmCarStateByCarId(carId);
        return AjaxResult.success(hmCarState);
    }

//    /**
//     * 新增车辆状态
//     */
//    @PreAuthorize("@ss.hasPermi('train:state:add')")
//    @Log(title = "车辆状态", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody HmCarState hmCarState)
//    {
//        return toAjax(hmCarStateService.insertHmCarState(hmCarState));
//    }

    /**
     * 修改车辆状态
     */
    @Log(title = "车辆状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HmCarState hmCarState) {
        int result = hmCarStateService.updateHmCarState(hmCarState);
        if (result == -1) {
            return AjaxResult.error("当前用户未绑定车辆");
        } else {
            return toAjax(result);
        }
    }


//    /**
//     * 删除车辆状态
//     */
//    @PreAuthorize("@ss.hasPermi('train:state:remove')")
//    @Log(title = "车辆状态", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{carIds}")
//    public AjaxResult remove(@PathVariable Long[] carIds)
//    {
//        return toAjax(hmCarStateService.deleteHmCarStateByCarIds(carIds));
//    }
}
